<?php

namespace Common\Model;

use Think\Model;

class ClassifyModel extends Model {

    protected $_validate = array(/* array(验证字段1,验证规则,错误提示,[验证条件,附加规则,验证时间]) */
        array('name', 'require', '名称不能为空'),
        //array('name', '', '名称已存在', 0, 'unique'),
    );  // 自动验证定义
    

    public function addClassify($data = '') {
        $rt = false;
		//!empty($data['img'])?$data['img']=$this->get_url_path($data['img']):"";
        if ($this->create($data)) {
            $rt = $this->add();
        }
        return $rt;
    }

    public function updateClassify($data = '') {
        $rt = false;
		//var_dump($data);exit;
		//!empty($data['img'])?$data['img']=$this->get_url_path($data['img']):"";
        if ($this->create($data)) {
            $rt = $this->save();
			if($rt===false){
				$rt=false;
			}else{
				$rt=true;
			}
        }
        return $rt;
    }

    public function deleteClassify($classifyID) {
        if ($classifyID <= 0) {
            $this->error = "无效ID";
            return false;
        }
        return $this->where("classifyID=$classifyID")->delete();
    }

    public function getClassifyById($classifyID) {
        if ($classifyID <= 0) {
            $this->error = "无效";
            return false;
        }
        return $this->where("classifyID=$classifyID")->find();
    }

    public function getClassifyList($pageNo = 1, $pageSize = 15, $where = array(), $order = array()) {
		
        $rt = $this->where($where)->page("$pageNo,$pageSize")->order($order)->select();
        return $rt;
    }
	

    public function getClassifyListLength($where = array()) {
        $count = $this->where($where)->count();
        return $count;
    }
	
	private function get_url_path($url){
    	$fUrl=parse_url($url);
    	return $fUrl['path'];
    }

}

?>